package com.imooc.web;

import com.fasterxml.jackson.annotation.JsonView;
import com.imooc.dto.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping
    @JsonView(User.SimpleViewUser.class)
    public List<User> list() {
        User user = new User();
        User user2 = new User();
        User user1 = new User();

        ArrayList<User> users = new ArrayList<>();
        users.add(user);
        users.add(user1);
        users.add(user2);

        return users;
    }

    @GetMapping("/{id:\\d+}")
    @JsonView(User.DetailViewUser.class)
    public User getUser(@PathVariable String id) {

        User user = new User();
        user.setUsername("tom");

        return user;
    }

}
